<?php
/**
 * 定义 Table_Orders 类
 *
 * @author sunnycoolboy
 * @package leadtone
 * @version $Id: Orders.php 2008-12-21 16:47:05
 */
FLEA::loadClass('FLEA_Db_TableDataGateway');
class Model_User extends FLEA_Db_TableDataGateway
{
	
	var $_tbUser;

    /**
     * 构造函数
     *
     * @return Model_Articles
     */
    function Model_User() {
        $this->_tbUser =& FLEA::getSingleton('Table_User');
    }

    /**
     * 获取指定 ID 的产品信息
     *
     * @param int $articleId
     * @param boolean $withAssoc 指示是否获取产品的关联信息（分类及照片）
     *
     * @return array
     */
    function getUser($uid, $withAssoc = true) {
        $link =& $this->_tbUser->getLink('department');
        $link->enabled = $withAssoc;

        return $this->_tbUser->find((int)$uid);
    }

    /**
     * 保存产品信息
     *
     * @param array $article
     *
     * @return boolean
     */
    function saveUser($user) {
        if (isset($user['uid']) && (int)$user['uid'] == 0) {
            unset($user['uid']);
        }
        return $this->_tbUser->save($user);
    }

    /**
     * 删除指定的文章信息
     *
     * @param int $articleId
     *
     * @return boolean
     */
    function removeUser($uid) {
    	
        $uid = (int)$uid;

        $user = $this->_tbUser->find($uid);

        if (!$user) {
            FLEA::loadClass('Exception_ArticleNotFound');
            __THROW(new Exception_ArticleNotFound($uid));
            return false;
        }

        return $this->_tbUser->removeByPkv($uid,false);
    }


    /**
     * 返回 Table_Articles 对象
     *
     * @return Table_Articles
     */
    function & getTable() {
        return $this->_tbUser;
    }
}
